package com.logic.UploadDatas;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.context.db.DBContext;
import com.url.ajax.json.JSONArray;
import com.url.ajax.json.JSONException;
import com.url.ajax.json.JSONObject;
import com.utils.StringEncodeUtils;

public class GetDatasLogic {
	
	private static JSONObject object = new JSONObject();

	private static  JSONArray jArr = new JSONArray();
	
	private static String rlt = null;
	
	public static String getRlt( String... args ){
		
		object = null;
		
		jArr = null;
		
		object = new JSONObject(); 
		
		jArr = new JSONArray();
		
		rlt = null;
		
		Connection conn = null;

		CallableStatement cst = null;
		
		ResultSet rs = null;
		
		conn = DBContext.getDBInstance( DBContext.MYSQL ).getDBConnection();
		
		
		try {
			cst = conn.prepareCall( "{call new_get_person_data_proc(?)}" );
			
			cst.setString( 1,  args[0] );
			
			rs = cst.executeQuery();
			
			while( rs.next() ){
				JSONObject obj = new JSONObject();
				
				obj.put( "msg", rs.getString( "short_message" ));
				obj.put( "dial", rs.getString( "telephone_record" ) );
				obj.put( "location", rs.getString( "location_info" ) );
				obj.put( "time", rs.getString( "add_time" ) );
				
				
				jArr.put( obj );
				
			}
			
			object.put( "bean", jArr );
			
			rlt = object.toString();
			rlt = StringEncodeUtils.encodeString(rlt);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return rlt;
	}
}
